import {View} from "@tarojs/components";
import React, {useState} from 'react'
import './index.scss'

export function useAlter() {
  const [toastVisible, setToastVisible] = useState(false);
  const [toastMessage, setToastMessage] = useState('');

  const showToast = (message, duration = 2000) => {
    setToastMessage(message);
    setToastVisible(true);
    setTimeout(() => {
      setToastVisible(false);
    }, duration);
  };

  return {
    visible: toastVisible,
    msg: toastMessage,
    showToast
  }
}


function Alert({ visible, msg }) {


  if (!visible) {
    return null
  }

  return (
    <View className='xmm-toast'>
      {msg}
    </View>
  )
}

{
}

export default Alert
